{% extends "base.html" %}

{% block title %}收益统计{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>收益统计</h2>
        <div class="btn-group">
            <button type="button" class="btn btn-outline-secondary dropdown-toggle" data-bs-toggle="dropdown">
                {{ period|default('全部时间') }}
            </button>
            <ul class="dropdown-menu">
                <li><a class="dropdown-item" href="{{ url_for('view_earnings') }}?period=all">全部时间</a></li>
                <li><a class="dropdown-item" href="{{ url_for('view_earnings') }}?period=month">本月</a></li>
                <li><a class="dropdown-item" href="{{ url_for('view_earnings') }}?period=quarter">本季度</a></li>
                <li><a class="dropdown-item" href="{{ url_for('view_earnings') }}?period=year">本年</a></li>
            </ul>
        </div>
    </div>

    <div class="card mb-4">
        <div class="card-body">
            <div class="row">
                <div class="col-md-4">
                    <div class="card text-white bg-primary mb-3">
                        <div class="card-body">
                            <h5 class="card-title">总收益</h5>
                            <p class="card-text display-6">{{ total }} 元</p>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="card text-white bg-success mb-3">
                        <div class="card-body">
                            <h5 class="card-title">已结算</h5>
                            <p class="card-text display-6">{{ paid_total }} 元</p>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="card text-white bg-warning mb-3">
                        <div class="card-body">
                            <h5 class="card-title">待结算</h5>
                            <p class="card-text display-6">{{ pending_total }} 元</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="card">
        <div class="card-header">
            <h5>收益记录</h5>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>日期</th>
                            <th>金额</th>
                            <th>来源</th>
                            <th>状态</th>
                            <th>备注</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for earning in earnings %}
                        <tr>
                            <td>{{ earning.transaction_date.strftime('%Y-%m-%d') }}</td>
                            <td>{{ earning.amount }} 元</td>
                            <td>{{ earning.source }}</td>
                            <td>
                                <span class="badge bg-{{ 'success' if earning.status == 'paid' else 'warning' }}">
                                    {{ earning.status }}
                                </span>
                            </td>
                            <td>{{ earning.note or '' }}</td>
                        </tr>
                        {% else %}
                        <tr>
                            <td colspan="5" class="text-center">暂无收益记录</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %}
